package org.kl.wxWeb.web;

import java.util.List;
import java.util.Map;

import javax.servlet.ServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.kl.bf.entity.basic.Config;
import org.kl.bf.service.basic.ConfigService;
import org.kl.bf.utils.KLServlets;
import org.kl.bf.web.base.BasicController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springside.modules.web.MediaTypes;

/**
 * 系统配置
 * 
 * @Author hqm
 * @CreateTime 2014-3-13 下午9:34:36
 */
@Controller
@RequestMapping(value = "/wxWeb/wxConfig")
public class WxConfigController extends BasicController {
	@Autowired
	private ConfigService configService;

	@RequestMapping(method = RequestMethod.GET)
	public String list(@RequestParam(value = "openid", defaultValue = "") String openid,
			@RequestParam(value = "appid", defaultValue = "") String appid, Model modle) {
		if (StringUtils.isBlank(openid) || StringUtils.isBlank(appid)) {
			return "error/wxWeb119";
		}
		return "/wxWeb/wxConfigList";
	}

	@RequestMapping(value = "dataGrid", produces = MediaTypes.JAVASCRIPT_UTF_8)
	@ResponseBody
	public String dataGrid(Model model, ServletRequest request) {
		Map<String, Object> searchParams = KLServlets.getParametersStartingWith(request, SEARCH_PREFIX);
		// Map<String, String> dataDetailMap =
		// BasicController.getCurrentUserDataDetail();
		// System.out.println(dataDetailMap.toString());
		// Page<Config> configs = configService.getUserConfig(searchParams,
		// pageNumber, pageSize, sortType, orderType);
		// WxUser wxUser = wxUserService.getByAppIdAndOpenid(appid, openid);
		// if (StringUtils.isBlank(wxUser.getUnionid())) {
		// return EasyuiUtils.buildEasyuiGridJsonString(null, 0);
		// }
		// User u = userService.getUser(wxUser.getUnionid());
		// if (u == null || StringUtils.isBlank(u.getId())) {
		// return EasyuiUtils.buildEasyuiGridJsonString(null, 0);
		// }
		List<Config> configList = configService.searchAll(searchParams);
		return jsonMapper.toJson(configList);
	}
}
